#include<iostream>
#include<fstream>
#include<string>

using Str=std::string;

void skipLineComment(std::ifstream&s){
    char temp=42;
    while(temp&&temp!='\n')s>>temp;
}
void skipBlockComment(std::ifstream&ifs){
    char temp=42;
    while(ifs.good()){
        ifs>>temp;
        if(temp=='*'){
            if(ifs.peek()=='/')
            ifs>>temp;
            break;
        }
    }
}
void CommentDelete(Str const&fileName,Str const&out){
    std::ifstream ifs(fileName);
    std::ofstream ofs(out,std::ios::trunc);
    ifs>>std::noskipws;
    // /**state
    //  * 0 -- normal
    //  * 1 -- line comment
    //  * 2 -- block comment
    // */
    // short state=0;
    char temp=42,next;
    while(ifs.good()){// / *
        ifs>>temp;
        if(temp=='/'){
            switch(ifs.peek()){
                case '/':
                    ifs>>temp;
                    skipLineComment(ifs);
                    break;
                case '*':
                    ifs>>temp;
                    skipBlockComment(ifs);
                    break;
                default:
                    ofs<<temp;
            }
        }else{
            ofs<<temp;
        }
    }
    ifs.close();
    ofs.close();
}
void CommentDelete(Str const&fileName){
    Str out=fileName,prefix,postfix;
    bool pre=true;
    size_t idx=fileName.find_last_of('.');
    if(idx==Str::npos){
        prefix=fileName;
    }else{
        prefix=fileName.substr(0,idx);
        postfix=fileName.substr(idx);
    }
    CommentDelete(fileName,prefix+"1"+postfix);
}
int main(){
    CommentDelete("main.cpp");
    return 0;
}
